import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { generateDocument } from './doc';
import { NestExpressApplication } from '@nestjs/platform-express';
import { join } from 'path';
const port = process.env.APP_PORT; //设置端口号
async function bootstrap() {
  const app = await NestFactory.create<NestExpressApplication>(AppModule);
  // 创建文档
  generateDocument(app);
  app.enableCors();
  const uploadDir =
    !!process.env.UPLOAD_DIR && process.env.UPLOAD_DIR !== ''
      ? process.env.UPLOAD_DIR
      : join(__dirname, '..', 'static/upload');
  // 静态服务
  app.useStaticAssets(uploadDir, {
    prefix: '/static/upload',
  });
  await app.listen(port, () => {
    console.log(`服务:                http://localhost:${port}`);
    console.log(`swagger-ui接口文档:  http://localhost:${port}/api/doc`);
    console.log(`knife4j 接口文档:     http://localhost:${port}/doc.html`);
  });
}
bootstrap();
